import { defHttp } from '@/utils/http/axios';
import {
  loginAuth,
  AccountParams,
  AccountListGetResultModel,
  AuthRoleListGetResultModel,
  AccountAuthListGetResultModel,
  SubAccountParams,
  LogParams,
} from './model/accountModel';

enum Api {
  LOGIN = '/auth',
  SUB_ACCOUNT = '/api/admin/v1/admin-user/list',
  SUB_ACCOUNT_AUTH_LIST = '/api/admin/v1/admin-role/auth',
  ADD_SUB_ACCOUNT = '/api/admin/v1/admin-user/add',
  EDIT_SUB_ACCOUNT = '/api/admin/v1/admin-user/edit',
  EDL_SUB_ACCOUNT = '/api/admin/v1/admin-user/del',
  AUTH_ROLE = '/api/admin/v1/admin-role/list',
  ADD_AUTH_ROLE = '/api/admin/v1/admin-role/add',
  EDIT_AUTH_ROLE = '/api/admin/v1/admin-role/edit',
  DEL_AUTH_ROLE = '/api/admin/v1/admin-role/del',
  LOG_ADMIN = '/api/admin/v1/admin-log/list',
  LOG_ADMIN_MODULE = '/api/admin/v1/admin-log/menu-module',
  RoleUserList = '/api/admin/v1/admin-user/role_user_list',
}

/**
 * @description: Get user menu based on id
 */

export const login = () => {
  return defHttp.post<loginAuth>({ url: Api.LOGIN });
};

export const getAccountList = (params?: AccountParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.SUB_ACCOUNT, params });

export const getAccountAuthList = (params?: { id: number | string }) =>
  defHttp.get<AccountAuthListGetResultModel>({ url: Api.SUB_ACCOUNT_AUTH_LIST, params });

export const delAccountItem = (params?: { id: number | string }) =>
  defHttp.delete({ url: Api.EDL_SUB_ACCOUNT, params });

export const getAuthRoleList = (params?: { role?: string; status: number | string }) =>
  defHttp.get<AuthRoleListGetResultModel>({ url: Api.AUTH_ROLE, params });

export const addSubAccount = (params: SubAccountParams, headers: { AccessId: number }) =>
  defHttp.post({ url: Api.ADD_SUB_ACCOUNT, params, headers });

/**
 * 修改账号
 * @param params
 * @param headers
 */
export const editSubAccount = (params: SubAccountParams, headers: { AccessId: number }) =>
  defHttp.put({ url: Api.EDIT_SUB_ACCOUNT, params, headers });

export const addAuthRoleItem = (params: SubAccountParams, headers: { AccessId: number }) =>
  defHttp.post({ url: Api.ADD_AUTH_ROLE, params, headers });

export const editAuthRoleItem = (params: SubAccountParams, headers: { AccessId: number }) =>
  defHttp.put({ url: Api.EDIT_AUTH_ROLE, params, headers });

export const delAuthRoleItem = (params: { id: number | string }, headers: { AccessId: number }) =>
  defHttp.delete({ url: Api.DEL_AUTH_ROLE, params, headers });

export const getAdminLog = (params: LogParams) => defHttp.get({ url: Api.LOG_ADMIN, params });

export const getAdminModule = () => defHttp.get({ url: Api.LOG_ADMIN_MODULE });

/**
 * 获取角色用户列表
 * @param params
 */
export const getRoleUserList = (params: { role_id: number }) =>
  defHttp.get({ url: Api.RoleUserList, params });
